package com.example.administrator.waitan.find.art.ArtContentActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.base.BaseActivity;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/16.
 */
public class WomanContentActivity extends BaseActivity {
    private ListView mListView;
    private WomanContentBaseAdapter mAdapter;
    private List<WomanContentInfo> info;
    private RequestQueue queue;
    private String url = "http://a.17173.com/api/photos/detail?photosID=";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_woman_content);
        mListView = (ListView) findViewById(R.id.lv_women_content);
        Intent intent = getIntent();
        Integer ID = intent.getIntExtra("ID", 0);//设置没接收到参数默认为0
        String title = intent.getStringExtra("title");
        String imgUrl = url + String.valueOf(ID);
        TextView mTv = (TextView) findViewById(R.id.tv_women_content_title);
        mTv.setText(title);
        findViewById(R.id.btn_womenContent_return).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        queue = Volley.newRequestQueue(this);
        StringRequest request = new StringRequest(imgUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                WomanContentBeans beans = gson.fromJson(response, WomanContentBeans.class);
                info = new ArrayList<>();
                for (int i = 0; i < beans.getData().getList().size(); i++) {
                    info.add(beans.getData().getList().get(i));
                }
                mAdapter = new WomanContentBaseAdapter(info, WomanContentActivity.this);
                mListView.setAdapter(mAdapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        queue.add(request);
    }
}
